<!--
 * @Author: Freude Xu
 * @Date: 2021-10-05 17:52:56
 * @LastEditors: Freude Xu
 * @LastEditTime: 2021-10-05 18:06:54
 * @Description: 
-->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>小天使案例</title>
    <style>
        img {
            position: absolute;
            width: 100px;
        }
    </style>
</head>

<body>

    <img src="/Web课后练习成果/images/小企鹅.gif" alt="">
    <script>
        var pic = document.querySelector('img');
        document.addEventListener('mousemove', function(e) {
            //只要鼠标移动就触发事件
            // console.log('1');
            //原理：每次鼠标移动，我们就会获得最新的鼠标坐标，把这个x和y作为图片的top和left值就可以移动图片
            var x = e.pageX;
            var y = e.pageY;
            //记得拼接px单位
            pic.style.left = x - 25 + 'px';
            pic.style.top = y - 25 + 'px';
        })
    </script>
</body>

</html>